rm(list = ls())
library(raster)
library(rgdal)
library(sp)
grid<- readGDAL("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Covariates/covars.tif")
grid
rm(list = ls())
area  <- raster("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Forest_area/Raster/area1.tif")
ser<-raster("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Covariates/ser.tif")
sret<-raster("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Covariates/sret.tif")
elev<-raster("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Covariates/elev1000.tif")
wstress<-raster("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Covariates/wstress.tif")
fpres<-raster("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Covariates/fpres.tif")
ph<-raster("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Covariates/ph.tif")
ser<-as.factor(ser)
test<-stack(area,ser,elev, wstress, ph, fpres)
test
ftype<-raster("C:/Users/Claudio PETUCCO/Documents/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Covariates/ftype.tif")
plot(ftype)
#This code estimates the ash volume spatial distribution using kriging with esternal drift.
#As dependent variable, we the observed #ash volume data from the national forest inventory  (donnees brutes).
#The data are subdivided into five subsamples according to the forest cover type in which the ash are observed.
#The forest type of the sample plot are: 1 broadleaves high forest, 2 broadleaves high forest & coppice, 3 broadleaves coppice,
#   5 conifers, 9 other.
# For each forest type, we fit a linear regression model using the following independent variables (see paper for full references):
# 1)the soil water deficit as defined in Piedallu et al (2016), obtained from the portal on forest spatial data SILVAE (LERFoB and IFN, 2008)
# 2)the soil pH obtained from the portal on forest spatial data SILVAE (LERFoB and IFN, 2008),
# 3)the elevation (Institut national de l'information géographique et forestière - IGN)
# 4)a categorical variable representing the 86 diferent types of ecological regions present in French forests (SER), obrained from
#   Institut national de l'information géographique et forestière - IGN
#
# All these data were aggregated to a single spatial dataset for each forest type (allplot_ft1, allplot_ft2, allplot_ft3, allplot_ft5,
# allplot_ft9), Once the regression models are estimated, the we plot the experimental variogram and fit a theorical variogram to the data
#
# Using the estimated models, we predict the forest volume distribution for a 1000x1000 m grid covering the entire french territory.
# Using the independent variables spatial data, we assign to each pixel a value for the independent variable (covars.tif). All the pixel
# not containing forest areas were set as NA
#
# Once we obrained the raster with the agerage volume per hectare for each pixel (within each forest type), we multiply it by the
# raster with the total forest area per pixel (within each forest type)
rm(list = ls())
# spatial
library(raster)
library(rgdal)
library(sp)
#geostatistics
library(gstat)
#input repository
input_dir<-c("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Plots/")
covar_dir<-c("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Covariates/")
area_dir<-c("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Forest_area/Raster/")
#output repository
output_dir<-c("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Results/Output_ked/")
#========================================================================================================================
# KRIGINg WITH SER
#========================================================================================================================
#====== FTYPE 1 - Broadleaved high forest ===============================================================================
#import sample plot data data
Ash_START <- read.csv(paste0(input_dir,"allplot_ft1.csv"))
View(Ash_START)
View(Ash_START)
names(Ash_START)
#This code estimates the ash volume spatial distribution using kriging with esternal drift.
#As dependent variable, we the observed #ash volume data from the national forest inventory  (donnees brutes).
#The data are subdivided into five subsamples according to the forest cover type in which the ash are observed.
#The forest type of the sample plot are: 1 broadleaves high forest, 2 broadleaves high forest & coppice, 3 broadleaves coppice,
#   5 conifers, 9 other.
# For each forest type, we fit a linear regression model using the following independent variables (see paper for full references):
# 1)the soil water deficit as defined in Piedallu et al (2016), obtained from the portal on forest spatial data SILVAE (LERFoB and IFN, 2008)
# 2)the soil pH obtained from the portal on forest spatial data SILVAE (LERFoB and IFN, 2008),
# 3)the elevation (Institut national de l'information géographique et forestière - IGN)
# 4)a categorical variable representing the 86 diferent types of ecological regions present in French forests (SER), obrained from
#   Institut national de l'information géographique et forestière - IGN
#
# All these data were aggregated to a single spatial dataset for each forest type (allplot_ft1, allplot_ft2, allplot_ft3, allplot_ft5,
# allplot_ft9), Once the regression models are estimated, the we plot the experimental variogram and fit a theorical variogram to the data
#
# Using the estimated models, we predict the forest volume distribution for a 1000x1000 m grid covering the entire french territory.
# Using the independent variables spatial data, we assign to each pixel a value for the independent variable (covars.tif). All the pixel
# not containing forest areas were set as NA
#
# Once we obrained the raster with the agerage volume per hectare for each pixel (within each forest type), we multiply it by the
# raster with the total forest area per pixel (within each forest type)
rm(list = ls())
# spatial
library(raster)
library(rgdal)
library(sp)
#geostatistics
library(gstat)
#input repository
input_dir<-c("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Plots/")
covar_dir<-c("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Covariates/")
area_dir<-c("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Forest_area/Raster/")
#output repository
output_dir<-c("~/LEF/Dottorato/Case_studies/Chalara/Data/Ash_distribution/FFSM_input/Kriging/Results/Output_ked/")
#========================================================================================================================
# KRIGINg WITH SER
#========================================================================================================================
#====== FTYPE 1 - Broadleaved high forest ===============================================================================
#import sample plot data data
Ash_START <- read.csv(paste0(input_dir,"allplot_ft1.csv"))
dat<-data.frame(x=Ash_START$X, y=Ash_START$Y, vol=Ash_START$vol, ftype=factor(Ash_START$ftype_plot), elev=Ash_START$elev,
soil=factor(Ash_START$soil), sret=Ash_START$sret3035, yret=Ash_START$yret3035, ser=factor(Ash_START$numser),
wstress=Ash_START$wstress, ph=Ash_START$ph)
